package com.kitty.game.fight.factory.model;

import com.kitty.game.role.model.Role;
import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.fight.message.RespCombatFriends;
import com.kitty.game.fight.message.RespCombatOpponets;
import com.kitty.game.fight.message.vo.FightMember;
import com.kitty.game.task.model.product.entry.FightSide;
import com.kitty.game.team.model.Member;
import com.kitty.game.team.model.Team;
import org.nutz.lang.util.NutMap;

import java.util.ArrayList;
import java.util.List;

public class MirrorFight extends Fight {
    private FightSide fightSide;

    private ArrayList<FightMember> fightMemberA = new ArrayList<>();

    private List<Member> list;

    private Role role;

    private Team team;

    public MirrorFight(int type, int npcId, Role role, FightSide enemyFightSide) {
        super(type);
        this.fightSide = enemyFightSide;
        this.role = role;
        setMapId(role.getPos().getMapId());
        setNpcId(npcId);
    }

    @Override
    protected void loadActors() {
        team = fightService.getRoleFightTeam(role);
        list = fightService.loadTeamBattleInfo(team, fightMemberA, this);
    }

    @Override
    protected void notifyAndStart() {
        RespCombatFriends respCombatFriends = new RespCombatFriends();
        respCombatFriends.setCustomIconList(getCustomIconListA());

        RespCombatOpponets respCombatOpponets = new RespCombatOpponets();
        respCombatOpponets.setCustomIconList(getCustomIconListB());

        ArrayList<FightMember> monsterListB = fightSide.getFightMemberList();
        ArrayList<FightObject> memberListB = fightSide.getFightObjectList();

        setBossReward(new NutMap());
        getBossReward().setv("size", monsterListB.size());
        // 写入野外战斗怪物给的经验
        setExpMap(new NutMap().setv("exp", fightSide.getExp()));

        respCombatOpponets.setList(monsterListB);
        respCombatFriends.setList(fightMemberA);
        setListB(memberListB);

        fightService.sendStartCombat(respCombatFriends, respCombatOpponets, list);
        if (fightSide.getFightMsg() != null) {
            SpringUtils.getTeamService().pushMessageToTeam(team, fightSide.getFightMsg());
        }
        fightService.whileSendStart(this);
        for (FightObject fightObject : getListA()) {
            if (fightObject.isPlayer()) {
                fightService.autoFightOne(this, fightObject);
            }
        }
    }
}
